<template>
  <div id="safe_audit">
    <p>页面数据的百分比:<el-progress :text-inside="true"  :stroke-width="24" :percentage="max" status="success"></el-progress></p>
    <!-- 查询条件 -->
    <el-form :inline="true" :model="info" class="demo-form-inline">
      <el-form-item label="请选择仓库id:">
        <el-input v-model="info.search_gatherId" placeholder="入库单id"></el-input>
      </el-form-item>
      <el-form-item label="请选择入库人:">
        <el-input v-model="info.search_storer" placeholder="入库人"></el-input>
      </el-form-item>
      <el-form-item label="请选择申请人:">
        <el-input v-model="info.search_register" placeholder="申请人"></el-input>
      </el-form-item>
      <el-form-item label="请输入审核时间" required>
        <el-col :span="11">
          <el-form-item prop="date1">

            <el-date-picker type="datetime" v-model="info.search_checkTime1" placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-form-item prop="date2">
            <el-date-picker type="datetime" v-model="info.search_checkTime2" placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="search" round>查询按钮</el-button>
<!--        <el-button type="success" @click="showById3()" round>添加</el-button>-->
      </el-form-item>
    </el-form>
    <!--    入库管理-->
    <el-table :data="arrList1" style="width: 100%">
      <el-table-column prop="gatherId" label="入库单id" width="150">
      </el-table-column>
      <el-table-column prop="gatherOrderNumber" label="入库单编号" width="150">
      </el-table-column>
<!--      <el-table-column prop="stockId" label="仓库id" width="150">-->
<!--      </el-table-column>-->
      <el-table-column prop="storer" label="入库人" width="150">
      </el-table-column>
      <el-table-column prop="reason" label="入库理由" width="150">
      </el-table-column>
      <el-table-column prop="totalAmount" label="总数量" width="150">
      </el-table-column>
      <el-table-column prop="totalPrice" label="总价格" width="150">
      </el-table-column>
      <el-table-column prop="purchaseId" label="采购订单id" width="150">
      </el-table-column>
      <el-table-column prop="checkTag" label="审核状态" width="150">
        <template slot-scope="scope">
          {{ scope.row.checkTag == "S001-3" ? "审核通过" : (scope.row.checkTag == "S001-2" ? "审核未通过" : "等待审核") }}
        </template>
      </el-table-column>
      <!--操作列-->
<!--      <el-table-column label="修改" style="width: 50%">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button size="mini" type="success" @click="showById(scope.$index, scope.row)" round>修改</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="审核" style="width: 50%">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="showById2(scope.$index, scope.row)" round>审核</el-button>
        </template>
      </el-table-column>
<!--      <el-table-column label="删除" style="width: 50%">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button size="mini" type="danger" @click="open(scope.$index, scope.row)" round>删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <!-- 修改弹出对话框 -->
    <el-dialog title="入库申请修改" :visible.sync="dialogVisible" width="60%">
      <el-form :inline="true" :model="filebean" class="demo-form-inline">
        <el-form :inline="true" :model="filebean" class="demo-form-inline">
          <el-form-item label="入库单编号">
            <el-input v-model="filebean.gatherOrderNumber" placeholder="入库单编号"></el-input>
          </el-form-item>
          <el-form-item label="入库人">
            <el-input v-model="filebean.storer" placeholder="入库人"></el-input>
          </el-form-item>
          <el-form-item label="入库理由">
            <el-input v-model="filebean.reason" placeholder="入库理由"></el-input>
          </el-form-item>
          <el-form-item label="总数量">
            <el-input v-model="filebean.totalAmount" placeholder="总数量"></el-input>
          </el-form-item>
          <el-form-item label="总价格">
            <el-input v-model="filebean.totalPrice" placeholder="总价格"></el-input>
          </el-form-item>
          <el-form-item label="采购订单id">
            <el-input v-model="filebean.purchaseId" placeholder="采购订单id"></el-input>
          </el-form-item>
          <el-form-item label="审核人">
            <el-input v-model="filebean.checker" placeholder="审核人"></el-input>
          </el-form-item>
           <el-form-item label="审核时间">
          <el-input v-model="filebean.checkTime" class="demo-ruleForm" autocomplete="off" readonly></el-input>
        </el-form-item>
          <el-form-item label="审核理由">
            <el-input v-model="filebean.checkReason" placeholder="审核理由"></el-input>
          </el-form-item>
          <el-form-item label="审核理由">
            <el-input v-model="filebean.checkTag" placeholder="审核状态"></el-input>
            <template slot-scope="scope">
              {{ scope.row.checkTag === "S001-3" ? "审核通过" : (scope.row.checkTag === "S001-2" ? "审核未通过" : "等待审核") }}
            </template>
          </el-form-item>
        </el-form>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 添加弹出对话框 -->
    <el-dialog title="入库申请添加" :visible.sync="dialogVisibleAdd" width="60%">
      <el-form :inline="true" :model="showGather" class="demo-form-inline">
<!--        <el-form-item label="入库单编号">-->
<!--          <el-input v-model="showGather.gatherOrderNumber" placeholder="入库单编号"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="入库人">
          <el-input v-model="showGather.storer" placeholder="入库人"></el-input>
        </el-form-item>
        <el-form-item label="入库理由">
          <el-input v-model="showGather.reason" placeholder="入库理由"></el-input>
        </el-form-item>
        <el-form-item label="总数量">
          <el-input v-model="showGather.totalAmount" placeholder="总数量"></el-input>
        </el-form-item>
        <el-form-item label="总价格">
          <el-input v-model="showGather.totalPrice" placeholder="总价格"></el-input>
        </el-form-item>
        <el-form-item label="审核人">
          <el-input v-model="showGather.checker" placeholder="审核人"></el-input>
        </el-form-item>
         <el-form-item label="审核时间">
        <el-input v-model="showGather.checkTime" class="demo-ruleForm" autocomplete="off" readonly></el-input>
      </el-form-item>
        <el-form-item label="审核理由">
          <el-input v-model="showGather.checkReason" placeholder="审核理由"></el-input>
        </el-form-item>
        <el-form-item label="审核状态">
          <el-input v-model="showGather.checkTag" placeholder="审核状态"></el-input>
          <template slot-scope="scope">
            {{ scope.row.checkTag === "S001-3" ? "审核通过" : (scope.row.checkTag === "S001-2" ? "审核未通过" : "等待审核") }}
          </template>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleAdd = false">取 消</el-button>
          <el-button type="primary" @click="addGather">确 定</el-button>
      </span>
    </el-dialog>
    <!--    审核弹出对话框-->
    <el-dialog
        title=""
        :visible="dialogVisibleCheck"
        @close="dialogVisibleCheck = false"
    >
      <!-- 对话框内容 -->
      <h3 style="text-align: center;">入库审核</h3>
      <el-form :model="addForm">
        <!-- 添加 id 字段 -->
        <el-form-item label="入库单id" :label-width="formLabelWidth">
          <el-input v-model="addForm.gatherId" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="入库单编号" :label-width="formLabelWidth">
          <el-input v-model="addForm.gatherOrderNumber" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="入库人" :label-width="formLabelWidth">
          <el-input v-model="addForm.storer" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="入库理由" :label-width="formLabelWidth">
          <el-input v-model="addForm.reason" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="总数量" :label-width="formLabelWidth">
          <el-input v-model="addForm.totalAmount" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="总价格" :label-width="formLabelWidth">
          <el-input v-model="addForm.totalPrice" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="采购订单id" :label-width="formLabelWidth">
          <el-input v-model="addForm.purchaseId" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="审核人" :label-width="formLabelWidth">
          <el-input v-model="addForm.checker" autocomplete="off"></el-input>
        </el-form-item>
<!--        <el-form-item label="审核时间" :label-width="formLabelWidth">-->
<!--          <el-input v-model="addForm.checkTime" autocomplete="off">-->

<!--          </el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="审核理由" :label-width="formLabelWidth">
          <el-input v-model="addForm.checkReason" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleCheck = false">取 消</el-button>
        <el-button type="primary" @click="checkClass">复核通过</el-button>
      </div>
    </el-dialog>
    <!---分页组件-->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
                   :page-sizes="pageSizeList" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                   :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  created() {
    this.list()
  },
  data() {
    return {
      arrList1: [],
      info: {
        search_gatherId: '',
        search_storer: '',
        search_register: '',
        search_checkTime1: '',
        search_checkTime2: '',
      },
      // 当前页号
      currentPage: 1,
      // 当前页大小
      pageSize: 2,
      // 总记录数
      total: 0,
      // 页大小列表
      pageSizeList: [2, 5, 10, 20],
      dialogVisible: false,
      dialogVisibleCheck: false,
      dialogVisibleAdd: false,
      // 审核表单的对象
      addForm: {

      },
      //定义到对话框的值
      filebean: {

      },
      showGather: {

      },
      max:0,
      registerTime:"",
    }
  },
  methods: {
    async list() {
      const { data: res } = await this.$http.post
      (`/community/gather/show/${this.currentPage}/${this.pageSize}`)
      console.log('res',res)
      this.arrList1 = res.rows
      this.total = res.total
      let aaa=this.total/1
      if(aaa=="Infinity"){
        this.max=0
      }else{
        this.max=aaa
      }
    },
    async showById(index, row) {
      console.log('row',row)
      this.getdatatime()
      const { data: res } = await this.$http.post
      (`/community/gather/showById?gatherId=${row.gatherId}`)
      this.filebean = res
      this.dialogVisible = true
    },
    async showById2(index, row) {
      this.getdatatime();
      const { data: res } = await this.$http.post
      (`/community/gather/showById?gatherId=${row.gatherId}`)
      this.addForm = res
      this.dialogVisibleCheck = true
    },
    async showById3() {
      this.dialogVisibleAdd = true
    },
    //修改
    async edit(index, row) {
      console.log('row',row)
      const { data: res } = await this.$http.post
      (`/community/gather/updateById`,this.filebean)
      this.filebean = res
      this.dialogVisible = true
    },
    //add
    async addGather() {
      const { data: res } = await this.$http.post
      (`/community/gather/add`,this.showGather)
      this.showGather = res
      this.dialogVisibleAdd = true
    },
    async open(index, row) {
      try {
        await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        });
        const { data: res } = await this.$http.post(`/community/gather/del?gatherId=${row.gatherId}`);
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      } catch (error) {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      }
    },
    //发送复核请求
    async checkClass() {
      try {
        this.filebean.checkTime = this.getdatatime()
        const res = await this.$http.post(`/community/gather/update3`, this.addForm);
          console.log('res++++'+res)
          this.dialogVisibleCheck = false;
          this.$message('复核成功');
          await this.list();
      } catch (error) {
        console.error('Error in checkClass:', error);
        // 错误逻辑
      }
    },
    getdatatime () {
      var dt = new Date();
      var y = dt.getFullYear();
      var m = (dt.getMonth() + 1).toString().padStart(2, '0');
      var d = dt.getDate().toString().padStart(2, '0');
      var hh = dt.getHours().toString().padStart(2, '0');
      var mm = dt.getMinutes().toString().padStart(2, '0');
      var ss = dt.getSeconds().toString().padStart(2, '0');
      this.checkTime = `${y}-${m}-${d} ${hh}:${mm}:${ss}`
    },
    // 页大小改变
    handleSizeChange(val) {
      this.pageSize = val
      this.list()
    },
    // 页号改变
    handleCurrentChange(val) {
      this.currentPage = val
      // 重新查询
      this.list()
    },
  },

  // 表单查询
  search() {
    // 查询
    this.currentPage = 1
    this.list()
  },
}
</script>

<style></style>